/*
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package net.javlov.example.grid.landmarks;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Point;
import java.util.List;

import net.javlov.example.grid.GridWorldView;
import net.javlov.example.grid.SimpleGridWorld;

public class LandmarkView extends GridWorldView {

	private static final long serialVersionUID = 6615524844474359585L;
	
	Color[] colors;
	int dist;
	public LandmarkView(SimpleGridWorld w, int cellDim, int distance) {
		super(w, cellDim);
		colors = new Color[]{Color.red, Color.blue, Color.green, Color.orange, Color.magenta, Color.cyan, Color.pink};
		dist = distance;
	}
	
	@Override
	protected void drawOthers(Graphics2D g) {
		List<Point> marks = (List<Point>)model.getObjects();
		Point p = marks.get(0);
		//draw first landmark without area, since it can always be reached
		g.setColor(colors[0]);
		g.fillOval((int)((p.x + 0.25)*cellDim), (int)((p.y + 0.25)*cellDim),
				(int)(cellDim*0.5), (int)(cellDim*0.5));
		
		//draw the rest of the landmarks
		for ( int i = 1; i < marks.size(); i++ ) {
			p = marks.get(i);
			g.setColor(colors[i]);
			g.fillOval((int)((p.x + 0.25)*cellDim), (int)((p.y + 0.25)*cellDim),
					(int)(cellDim*0.5), (int)(cellDim*0.5));

			for (int h = p.y-dist; h < p.y+dist; h++)
	    		for (int w = p.x-dist; w < p.x+dist; w++)
	    			if ( (Math.abs(p.y-h) + Math.abs(p.x-w)) == dist )
	    				g.drawRect(w*cellDim, h*cellDim, cellDim, cellDim);

		}
	}

}
